﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace work
{
    public partial class AddGarde : Form
    {
        public AddGarde()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0 && textBox2.Text.Length == 0 && textBox3.Text.Length == 0)
            {
                MessageBox.Show("请输入完整信息");
            }
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=.;database=Schools;user id=sa;password=123";
            conn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "insert into Students  values('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "')";
            cmd.Connection = conn;

            cmd.ExecuteNonQuery();
            conn.Close();

            this.textBox1.Text = "";
            this.textBox2.Text = "";



            MessageBox.Show("添加成功");
            this.Hide();
            try
            {
                Form f = this.Owner;
                ((AllGrade)f).refresh();
            }
            catch
            {

            }
        }
    }
}
